/**
 * @FileName: Pageable.java
 * @Package: model.options.page
 * @author youshipeng
 * @created 2016/11/1 8:50
 * <p>
 * Copyright 2016 ziroom
 */
package top.swimmer.core.model.options.page;

/**
 * <p></p>
 *
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author youshipeng
 * @since 1.0
 * @version 1.0
 */
public class Pageable {
    private static final Integer DEFAULT_PAGING_SIZE = 20;
    private static final Integer DEFAULT_PAGING_START = 0;
    private static final String DEFAULT_ORDER_BY = "id";
    private static final String DEFAULT_ORDER = "asc";

    private Integer start;
    private Integer count;
    private String order;
    private String orderBy;

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public Integer getValidCount() {
        if (count == null || count < 0) {
            return DEFAULT_PAGING_SIZE;
        }
        return count;
    }

    public Integer getValidStart() {
        if (start == null || start < 0) {
            return DEFAULT_PAGING_START;
        }
        return start;
    }

    public String getValidOrder() {
        return order == null ? DEFAULT_ORDER : order;
    }

    public String getValidOrderBy() {
        return orderBy == null ? DEFAULT_ORDER_BY : orderBy;
    }

    public Integer nextStart() {
        return getValidStart() + getValidCount();
    }
}